package tk.mybatis.mapper.common.example.oper;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.util.Assert;

import tk.mybatis.mapper.mapperhelper.ExampleValidatorHelper;

public class OperBuilder {
	List<Oper> list;
	public Map<String, String> propertyMap;
	
	public OperBuilder(Class<?> clazz) {
		list = new ArrayList<Oper>();
		propertyMap = ExampleValidatorHelper.getExampleValidator(clazz).getPropertyMap();
	}
	
	/**
	 * count=count+1
	 * @param property
	 * @param number
	 * @return
	 */
	public OperBuilder increase(String property, Number number) {
		Oper oper = new IncreaseOper(property, number, propertyMap);
		list.add(oper);
		return this;
	} 
	
	/**
	 *  count=count-1
	 * @param property
	 * @param number
	 * @return
	 */
	public OperBuilder decrease(String property, Number number) {
		Oper oper = new DecreaseOper(property, number, propertyMap);
		list.add(oper);
		return this;
	}
	
	/**
	 * count=count*1
	 * @param property
	 * @param number
	 * @return
	 */
	public OperBuilder multiply(String property, Number number) {
		Oper oper = new MultiplyOper(property, number, propertyMap);
		list.add(oper);
		return this;
	} 
	
	/**
	 * count=count/1
	 * @param property
	 * @param number
	 * @return
	 */
	public OperBuilder divide(String property, Number number) {
		Oper oper = new DivideOper(property, number, propertyMap);
		list.add(oper);
		return this;
	} 
	
	/**
	 * count=value
	 * @param property
	 * @param value
	 * @return
	 */
	public OperBuilder eq(String property, Object value) {
		Oper oper = new EqualsOper(property, value, propertyMap);
		list.add(oper);
		return this;
	} 
	
	public OperBuilder custom(String property, String op) {
		Oper oper = new CustomOper(property, op, propertyMap);
		list.add(oper);
		return this;
	} 
	
	public OperBuilder add(Oper oper) {
		Assert.notNull(oper);
		list.add(oper);
		return this;
	} 
	
	public List<Oper> get() {
		return list;
	}
}